package vn.gq.udv.comic.fragment;

import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import vn.gq.udv.comic.BaseActivity;
import vn.gq.udv.comic.R;
import vn.gq.udv.tab.BaseFragment;

public class IntroFragment extends BaseFragment {

	public static IntroFragment newInstance() {
		IntroFragment f = new IntroFragment();
		return f;
	}
	
	@Override
	public int getContainerId() {
		return 0;
	}

	@Override
	public int getLayoutId() {
		return R.layout.webview_layout;
	}

	@Override
	public void createView() {
		final ProgressBar loading = (ProgressBar) mLayout.findViewById(R.id.loading);
		WebView webView = (WebView) mLayout.findViewById(R.id.webview);
		webView.loadUrl("file:///android_asset/data/intro.html");
		webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
		webView.setVerticalScrollBarEnabled(false);
		webView.setWebViewClient(new WebViewClient() {

			@Override
			public void onPageFinished(WebView webView, String url) {
				webView.setVisibility(View.VISIBLE);
				super.onPageFinished(webView, url);
				((BaseActivity) getActivity()).mHandler.postDelayed(new Runnable() {
					
					@Override
					public void run() {
						loading.setVisibility(View.GONE);
					}
				}, 1000);
			}
		});
	}

}
